<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>价格维护</title>
    <link rel="stylesheet" href="css/font-awesome.min.css"/>
    <link rel="stylesheet" href="css/font-awesome-ie7.min.css"/>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link href="css/jquery.datetimepicker.css" rel="stylesheet">
    <link rel="stylesheet" href="css/admin.css"/>

    <link rel="stylesheet" type="text/css" href="css/paging.css">

    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <![endif]-->
    <!--[if lt IE 10]>
    <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/jquery-placeholder/2.0.8/jquery.placeholder.min.js"></script>
    <![endif]-->
    <style>
        em {
            display: none;
        }

        .delimg {
            width: 20px;
            height: 20px;
            margin-left: 5px;
        }

        .delColimg {
            width: 20px;
            height: 20px;
            margin-left: 5px;
        }
    </style>
</head>
<body>
<div id="gray_bg"></div>
<!-- 添加单要素行开始 -->
<div id="editDiadog" class="diadog">
    <div class="diadog-tit">
        <div class="row">
            <div class="col-md-11" id="diadogTitle"><span>添加行</span></div>
            <div class="col-md-1 close"><span>×</span></div>
        </div>
    </div>
    <div class="diadog-con">
        <div class="form-horizontal" role="form">
            <div class="form-group">
                <label for="inputPassword3" class="col-md-3 control-label">要素名称:</label>
                <div class="col-sm-9">
                    <input id="rowName" type="text" class="form-control" style="display: inline">
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-md-3 control-label">价格:</label>
                <div class="col-sm-9">
                    <input id="singlePrice" type="text" class="form-control" style="display: inline">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-3 col-sm-9">
                    <button id="saveClass" type="submit" class="btn btn-danger">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 添加单要素行结束 -->
<!-- 添加双要素行开始 -->
<div id="franchiseDiadog" class="diadog">
    <div class="diadog-tit">
        <div class="row">
            <div class="col-md-11" id="rowTitle"><span>添加行</span></div>
            <div class="col-md-1 close"><span>×</span></div>
        </div>
    </div>
    <div class="diadog-con">
        <div class="form-horizontal" role="form">
            <div class="form-group">
                <label for="inputPassword3" class="col-md-3 control-label" id="colName">行要素名称:</label>
                <div class="col-sm-9">
                    <input id="doublerowName" type="text" class="form-control" style="display: inline">
                </div>
            </div>
            <div class="form-group" id="btn">
                <div class="col-sm-offset-3 col-sm-9">
                    <button id="saveRow" type="submit" class="btn btn-danger">保存</button>
                    <button id="saveCol" type="submit" class="btn btn-danger">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 添加双要素行结束 -->
<!-- header start -->
<div class="header">

</div>
<!-- header end -->
<!-- usercenter start -->
<div class="usercotent">
    <!-- left start -->
    <div id="center-left"></div>
    <!-- left end -->
    <!-- order right start -->
    <div class="usercotentr">
        <div class="user-tit" style="margin-bottom:10px">
            <h3>产品详情</h3>
        </div>
        <div class="downs" style="width: 960px !important;margin-top: 10px">
            <div class="row">
                <div class="col-md-2" style="width: 120px !important;">
                    <a style="width: 120px; height: 35px;margin-bottom: 20px;"
                       href="javascript:;" type="button" onclick="history.go(-1)" class="btn btn-primary">返回产品档案</a>
                </div>
                <div class="contract" style="margin-left: 20px">
                    <div class="col-md-12">
                        <div class="examline" style="border-bottom:1px solid #1abc9c">
                            <div class="exam-tit" style="background: #1abc9c;color: #fff;">基本信息</div>
                        </div>
                    </div>
                    <div class="col-md-3 iewidth210" style="margin-top:10px">
                        <strong class="ordertext">产品名称：</strong>
                        <span id="productName"></span>
                    </div>
                    <div class="col-md-3" style="margin-top:10px">
                        <strong class="ordertext" style="vertical-align: baseline">产品图片：</strong>
                        <img id="icon" src="" style="width: 100px;height:100px;vertical-align: top">
                    </div>
                    <div class="col-md-3" style="margin-top:10px">
                        <strong class="ordertext">产品描述：</strong>
                        <span id="description" style="line-height: 17px"></span>
                    </div>
                    <div class="col-md-12" style="margin-top:20px;">
                        <div class="examline" style="border-bottom:1px solid #2ecc71">
                            <div class="exam-tit" style="background: #2ecc71;color: #fff;float: left">价格信息</div>
                            <a style="width: 80px; height: 30px;line-height:13px;float: right" type="button"
                               class="btn btn-default" id="editSingle">编辑</a>
                            <a style="display:none;width: 80px; height: 30px;line-height:13px;float: right"
                               type="button" class="btn btn-default" id="saveSingle">保存</a>
                            <div class="clear"></div>
                        </div>
                    </div>
                    <div class="col-md-4 iewidth210" style="margin-top:10px">
                        <strong class="ordertext">报价主要素：</strong>
                        <span class="saveinfo" id="mainPriceFactor"></span>
                        <input type="text" id="e_mainPriceFactor" class="editinfo"
                               style="display:none;border: 1px solid black">
                    </div>
                    <div class="col-md-4 iewidth210" style="margin-top:10px">
                        <strong class="ordertext">价格列要素：</strong>
                        <span class="saveinfo" id="colPriceFactor"></span>
                        <input type="text" id="e_colPriceFactor" class="editinfo"
                               style="display:none;border: 1px solid black">
                    </div>
                    <div class="col-md-4 iewidth210" style="margin-top:10px">
                        <strong class="ordertext">价格行要素：</strong>
                        <span class="saveinfo" id="rowPriceFactor"></span>
                        <input type="text" id="e_rowPriceFactor" class="editinfo"
                               style="display:none;border: 1px solid black">
                    </div>
                    <div class="col-md-4 iewidth210" style="margin-top:10px">
                        <strong class="ordertext">价格标签：</strong>
                        <span class="saveinfo" id="priceLabel"></span>
                        <input type="text" id="e_priceLabel" class="editinfo"
                               style="display:none;border: 1px solid black">
                    </div>
                    <div class="col-md-4 iewidth210" style="margin-top:10px">
                        <strong class="ordertext">价格说明：</strong>
                        <span class="saveinfo" id="priceContent" style="line-height: 17px"></span>
                        <!--<input type="text" id="e_priceContent" class="editinfo" style="display:none;border: 1px solid black">-->
                        <textarea name="" id="e_priceContent" class="editinfo" style="display:none;border: 1px solid black;vertical-align: top;resize:none;" cols="20" rows="8"></textarea>
                    </div>
                    <div class="col-md-4 iewidth210" style="margin-top:10px">
                        <strong class="ordertext">报价方式：&nbsp;&nbsp;&nbsp;
                            <div id="radios" style="display: inline"><input id="single" name="chackbox" type="radio">单要素报价
                                &nbsp;&nbsp;&nbsp;
                                <input id="double" name="chackbox" type="radio">双要素报价
                            </div>
                        </strong>
                        <span id="single_s">单要素报价</span>
                        <span id="double_d">双要素报价</span>
                    </div>

                    <div id="singleTable" class="col-md-12" style="display: none">
                        <!--<a style="width: 80px; height: 30px;line-height:13px;float: right" type="button"-->
                        <!--class="btn btn-default" id="saveSingle">保存</a>-->
                        <a style="width: 80px; height: 30px;line-height:13px;float: right" type="button"
                           class="btn btn-default" id="addSingle">添加行</a>
                        <div class="clear"></div>
                        <div id="priceSingleList">
                            <div id="SingleList"
                                 style="width: 100%;height: auto;margin-top: 10px;overflow-x: auto;overflow-y: auto">
                                <table class="table table-bordered table-hover" style="margin-bottom: 0px">
                                    <thead id="singleCol">
                                    </thead>
                                    <tbody id="SingleListMyGrid">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div id="doubleTable" class="col-md-12" style="display: none">
                        <a style="width: 80px; height: 30px;line-height:13px;float: right" type="button"
                           class="btn btn-default" id="addcol">添加列</a>
                        <a style="width: 80px; height: 30px;line-height:13px;float: right" type="button"
                           class="btn btn-default" id="addrow">添加行</a>
                        <div class="clear"></div>
                        <div id="priceDoubleList">
                            <div id="DoubleList"
                                 style="width: 100%;height: auto;margin-top: 10px;overflow-x: auto;overflow-y: auto">
                                <table class="table table-bordered table-hover" style="margin-bottom: 0px">
                                    <thead id="doubleCol"></thead>
                                    <tbody id="DoubleListMyGrid">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- page start -->
            <!-- page end -->
        </div>

    </div>
    <!-- order right end -->
</div>

<!-- usercenter end -->

<!-- footer start -->
<div class="footer">
</div>
<!--判断用户的id-->
<input id="userID" type="hidden" value="">
<!--判断用户部门的id-->
<input id="iddeptID" type="hidden" value="">
<!--判断强制修改-->
<input id="permission" type="hidden" value="">
<!-- footer end -->
<script src="js/jquery.min-1-11-3.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/widget/myDataGrid.js"></script>
<script src="js/widget/admin.js"></script>
<script type="text/javascript" src="js/query.js"></script>
<script type="text/javascript" src="js/paging.js"></script>
<script type="text/javascript" src="bower_components/plupload/js/plupload.full.min.js"></script>
<script type="text/javascript" src="js/ui.js"></script>
<script type="text/javascript" src="js/qiniu.min.js"></script>
<script type="text/javascript" src="js/upload.js"></script>
<script src="js/widget/myOrderLayer.js"></script>
<script>
    $(function () {
        initSideAccMenu("产品管理", "产品维护");
        $.post("apis/product/getproductpriceinfo", {"productId": query("id")}, function (res) {
            var productInfo = res.data;
//            console.log(productInfo);
//            二维表格
            if (productInfo.colPriceFactor) {
                if (productInfo.priceInfoList.length == 0) {
                    $("#radios").hide();
                    $("#single_s").hide();
                    $("#double_d").hide();
                    $("#single").removeAttr("checked");
                    $("#double").removeAttr("checked");
                }
                else {
                    $("#radios").hide();
                    $("#single_s").hide();
                    $("#double_d").show();
                    $("#single").removeAttr("checked")
                    $("#double").attr("checked", "checked")

                    $("#doubleTable").show();
                    $("#addrow").hide();
                    $("#addcol").hide();
                    var thead = "";
                    var data = productInfo.priceInfoList;
                    thead = '<tr>' +
                        '<th style="background-color: #87CEFA;">' + productInfo.rowPriceFactor + '/' + productInfo.colPriceFactor + '</th>' +
                        '<th style="background-color: #87CEFA;"><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[0].priceInfo).price1 + '"><span class="thead" style="display: none">' + strToJson(data[0].priceInfo).price1 + '</span><em><img class="delColimg" src="img/del.png"></em></th>' +
                        '<th style="background-color: #87CEFA;"><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[0].priceInfo).price2 + '"><span class="thead" style="display: none">' + strToJson(data[0].priceInfo).price2 + '</span><em><img class="delColimg" src="img/del.png"></em></th>' +
                        '<th style="background-color: #87CEFA;"><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[0].priceInfo).price3 + '"><span class="thead" style="display: none">' + strToJson(data[0].priceInfo).price3 + '</span><em><img class="delColimg" src="img/del.png"></em></th>' +
                        '<th style="background-color: #87CEFA;"><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[0].priceInfo).price4 + '"><span class="thead" style="display: none">' + strToJson(data[0].priceInfo).price4 + '</span><em><img class="delColimg" src="img/del.png"></em></th>' +
                        '<th style="background-color: #87CEFA;"><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[0].priceInfo).price5 + '"><span class="thead" style="display: none">' + strToJson(data[0].priceInfo).price5 + '</span><em><img class="delColimg" src="img/del.png"></em></th>' +
                        '</tr>'
                    $("#doubleCol").append(thead);
                    var tbody = "";
                    for (var i = 1; i < data.length; i++) {
                        tbody += '<tr>' +
                            '<th style="background-color: #87CEFA;"><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[i].priceInfo).code + '"><span class="thead" style="display: none">' + strToJson(data[i].priceInfo).code + '</span></th>' +
                            '<td><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[i].priceInfo).price1 + '"><span class="thead" style="display: none">' + strToJson(data[i].priceInfo).price1 + '</span></td>' +
                            '<td><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[i].priceInfo).price2 + '"><span class="thead" style="display: none">' + strToJson(data[i].priceInfo).price2 + '</span></td>' +
                            '<td><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[i].priceInfo).price3 + '"><span class="thead" style="display: none">' + strToJson(data[i].priceInfo).price3 + '</span></td>' +
                            '<td><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[i].priceInfo).price4 + '"><span class="thead" style="display: none">' + strToJson(data[i].priceInfo).price4 + '</span></td>' +
                            '<td><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[i].priceInfo).price5 + '"><span class="thead" style="display: none">' + strToJson(data[i].priceInfo).price5 + '</span></td>' +
                            '</tr>'
                    }
                    $("#DoubleListMyGrid").append(tbody);
                    $(".init").hide();
                    $(".thead").show();
                    inputBlur();
                    undefind();
                }
            }
//            一维表格
            else {
                if (productInfo.priceInfoList.length == 0) {
                    $("#radios").hide();
                    $("#single_s").hide();
                    $("#double_d").hide();
                    $("#double").removeAttr("checked")
                    $("#single").removeAttr("checked")
                }
                else {
                    $("#radios").hide();
                    $("#single_s").show();
                    $("#double_d").hide();
                    $("#double").removeAttr("checked")
                    $("#single").attr("checked", "checked")
//                表格
                    $("#singleTable").show();
                    $("#addSingle").hide();
                    var thead = ""
                    thead = '<tr><th style="background-color: #87CEFA;">' + productInfo.rowPriceFactor + '</th><th style="background-color: #87CEFA;">价格</th></tr>'
                    $("#singleCol").append(thead)
                    var htmlsingle = ""
                    var data = productInfo.priceInfoList;
                    for (var i = 0; i < data.length; i++) {
                        htmlsingle += '<tr><th style="background-color: #87CEFA;"><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[i].priceInfo).code + '"><span class="thead" style="display: inline-block">' + strToJson(data[i].priceInfo).code + '</span></th><td><input class="init" type="text" style="width: 60px;display: none" value="' + strToJson(data[i].priceInfo).price1 + '"><span class="thead" style="display: inline-block">' + strToJson(data[i].priceInfo).price1 + '</span></td></tr>'
                    }
                    $("#SingleListMyGrid").append(htmlsingle);
                    inputBlur();
                }
            }
            $("#productName").html(productInfo.productName);
            $("#icon").attr("src", productInfo.icon);
            $("#description").html(productInfo.description);
            $("#mainPriceFactor").html(productInfo.mainPriceFactor);
            $("#colPriceFactor").html(productInfo.colPriceFactor);
            $("#rowPriceFactor").html(productInfo.rowPriceFactor);
            $("#priceLabel").html(productInfo.priceLabel);
            $("#priceContent").html(productInfo.priceContent);
        })
    })
    /*编辑价格信息*/
    $("#editSingle").click(function () {
        $(".init").show();
        $(".thead").hide();

        $("#editSingle").hide();
        $("#saveSingle").show();
        $(".editinfo").show();
        $(".saveinfo").hide();
        $("#radios").show();
        $("#single_s").hide();
        $("#double_d").hide();

        $("#e_mainPriceFactor").val($("#mainPriceFactor").html());
        $("#e_colPriceFactor").val($("#colPriceFactor").html());
        $("#e_rowPriceFactor").val($("#rowPriceFactor").html());
        $("#e_priceLabel").val($("#priceLabel").html());
        $("#e_priceContent").val($("#priceContent").html());
        if ($("#single").attr("checked")) {
            $("#addSingle").show();
        } else {
            $("#addrow").show();
            $("#addcol").show();
        }
        $("#DoubleListMyGrid tr th").append('<em><img class="delimg" src="img/del.png"></em>');
        $("#SingleListMyGrid tr th").append('<em><img class="delimg" src="img/del.png"></em>');
        /*删除行*/
        delRow();
        delCol();
    })
    /*选择报价方式*/
    $("#single").click(function () {
        $("#singleTable").show();
        $("#doubleTable").hide();
        $("#single").attr("checked", "checked");
        $("#double").removeAttr("checked");
        if ($("#e_rowPriceFactor").val() == "") {
            alert("请输入价格行要素")
            $("#addSingle").hide();
            $("#single").removeAttr("checked");
            return;
        } else {
            $("#addSingle").show();
        }
        var row = $("#e_rowPriceFactor").val();
        if ($("#singleCol tr:first th").html() == row) {
            return;
        }
        var singleTable = ""
        singleTable = '<tr><th style="background-color: #87CEFA;">' + row + '</th><th style="background-color: #87CEFA;">价格</th></tr>'
        $("#singleCol").append(singleTable);
        inputBlur();
    })
    $("#double").click(function () {
        $("#singleTable").hide();
        $("#doubleTable").show();
        $("#double").attr("checked", "checked");
        $("#single").removeAttr("checked");
        if ($("#e_colPriceFactor").val() == "" || $("#e_rowPriceFactor").val() == "") {
            alert("请输入价格行要素和价格列要素")
            $("#addrow").hide();
            $("#addcol").hide();
            $("#double").removeAttr("checked");
            return;
        } else {
            $("#addrow").show();
            $("#addcol").show();
        }
        var row = $("#e_rowPriceFactor").val();
        var col = $("#e_colPriceFactor").val();
        var head = row + "/" + col;
        if ($("#doubleCol").text() != "") {
            return;
        }
        var dthead = "";
        dthead = '<tr>' +
            '<th style="background-color: #87CEFA;height: 40px">' + head + '</th>' +
            '<th style="background-color: #87CEFA;"><input type="text" class="init" style="width: 60px"><span class="thead" style="display: none"></span><em><img class="delColimg" src="img/del.png"></em></th>' +
            '<th style="background-color: #87CEFA;"><input type="text" class="init" style="width: 60px"><span class="thead" style="display: none"></span><em><img class="delColimg" src="img/del.png"></em></th>' +
            '<th style="background-color: #87CEFA;"><input type="text" class="init" style="width: 60px"><span class="thead" style="display: none"></span><em><img class="delColimg" src="img/del.png"></em></th>' +
            '<th style="background-color: #87CEFA;"><input type="text" class="init" style="width: 60px"><span class="thead" style="display: none"></span><em><img class="delColimg" src="img/del.png"></em></th>' +
            '<th style="background-color: #87CEFA;"><input type="text" class="init" style="width: 60px"><span class="thead" style="display: none"></span><em><img class="delColimg" src="img/del.png"></em></th>' +
            '</tr>'
        $("#doubleCol").append(dthead);
        inputBlur();
        $(".init").show();
        $(".thead").hide();
        delCol();
    })
    /*单要素报价——添加行*/
    $("#addSingle").click(function () {
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#editDiadog").show();
        $("#editDiadog").center();

        $("#rowName").val("");
        $("#singlePrice").val("");
        $("#doublerowName").val("");
    })
    $("#saveClass").click(function () {
        var rowName = $("#rowName").val();
        var singlePrice = $("#singlePrice").val();
        var singleHtml = '<tr><th style="background-color: #87CEFA;height: 40px"><input class="init" type="text" style="width: 60px;display: none" value="' + rowName + '"><span class="thead" style="display: inline-block">' + rowName + '</span><em><img class="delimg" src="img/del.png"></em></th><td><input class="init" type="text" style="width: 60px;display: none" value="' + singlePrice + '"><span class="thead" style="display: inline-block">' + singlePrice + '</span></td></tr>';
        $("#SingleListMyGrid").append(singleHtml);
        $("#gray_bg").hide();
        $("#editDiadog").hide();
        inputBlur();
        $(".init").show();
        $(".thead").hide();
        delRow();
    })
    /*双要素报价——添加行*/
    $("#addrow").click(function () {
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#franchiseDiadog").show();
        $("#franchiseDiadog").center();
        $("#rowTitle").html("添加行");
        $("#colName").html("行要素名称");
        $("#saveRow").show();
        $("#saveCol").hide();

        $("#rowName").val("");
        $("#singlePrice").val("");
        $("#doublerowName").val("");
    })
    $("#saveRow").click(function () {
        var doubleRowName = $("#doublerowName").val();

        var tbody_rowName = '<tr>' +
            '<th style="background-color: #87CEFA;height: 40px"><input class="init" type="text" style="width: 60px;display: none" value="' + doubleRowName + '"><span class="thead" style="display: none;">' + doubleRowName + '</span><em><img class="delimg" src="img/del.png"></em></th>' +
            '</tr>';
        $("#DoubleListMyGrid").append(tbody_rowName);

        var collist = $("#doubleCol tr").children();
        var trow = "";
        for (var i = 0; i < collist.length - 1; i++) {
            trow += '<td><input type="text" class="init" style="width: 60px;"><span class="thead" style="display: none;"></span></td>';
        }
        $("#DoubleListMyGrid tr:last").append(trow);
        inputBlur();
        $(".init").show();
        $(".thead").hide();
        $("#gray_bg").hide();
        $("#franchiseDiadog").hide();
        //    删除行
        delRow();
    })
    //    双要素报价——添加列
    $("#addcol").click(function () {
        if ($("#doubleCol tr th").length == 6) {
            alert("表格不能超过五列");
            return;
        }
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#franchiseDiadog").show();
        $("#franchiseDiadog").center();
        $("#rowTitle").html("添加列");
        $("#colName").html("列要素名称");
        $("#saveRow").hide();
        $("#saveCol").show();

        $("#rowName").val("");
        $("#singlePrice").val("");
        $("#doublerowName").val("");
    })
    $("#saveCol").click(function () {
        var doubleColName = $("#doublerowName").val();
        var tbody_rowName = '<th style="background-color: #87CEFA;"><input class="init" type="text" style="width: 60px;display: none" value="' + doubleColName + '"><span class="thead" style="display: none;">' + doubleColName + '</span><em><img class="delColimg" src="img/del.png"></em></th>';
        $("#doubleCol tr").append(tbody_rowName);
        $("#gray_bg").hide();
        $("#franchiseDiadog").hide();

        var rowlist = $("#DoubleListMyGrid").children();
        var trow = "";
        for (var i = 0; i < rowlist.length; i++) {
            trow = '<td><input type="text" class="init" style="width: 60px;"><span class="thead" style="display: none;"></span></td>';
        }
        $("#DoubleListMyGrid tr").append(trow);
        inputBlur();
        $(".init").show();
        $(".thead").hide();
        $("#gray_bg").hide();
        $("#franchiseDiadog").hide();
        delCol();
    })

    /*保存*/
    $("#saveSingle").click(function () {
        undefind();
        $(".thead").show();
        $(".init").hide();
//        如果是一维表格
        if ($("#single").attr("checked")) {
            var list = [];
            var productInfo = {
                id: query("id"),
                productName: $("#productName").html(),
                mainPriceFactor: $("#e_mainPriceFactor").val(),
                rowPriceFactor: $("#e_rowPriceFactor").val(),
                colPriceFactor: "",
                priceLabel: $("#e_priceLabel").val(),
                priceContent: $("#e_priceContent").val(),
                priceInfoList: list
            }
            var rows = $("#SingleListMyGrid").children();
            for (var i = 0; i < rows.length; i++) {
                var rowX = {
                    headFlag: 0,
                    colCount: 1,
                    priceInfo: '{"code": "' + rows[i].cells[0].innerText + '" ,"price1":' + rows[i].cells[1].innerText + '}',
                    rowIndex: i + 1
                }
                list.push(rowX);
            }
            $.ajax({
                url: "apis/product/updateproductprice",
                type: 'post',
                data: {
                    "productInfo": JSON.stringify(productInfo)
                },
                dataType: 'json',
                success: function (data, status, xhr) {
                    if (data.httpCode == 200) {
                        $(".editinfo").hide();
                        $(".saveinfo").show();
                        $("#gray_bg").hide();
                        $("#editDiadog").hide();
                        window.location.reload();
                    } else {
                        alert(data.msg);
                    }
                }
            })
        }
//        如果是二维表格
        else {
            var list = [];
            var productInfo = {
                id: query("id"),
                productName: $("#productName").html(),
                mainPriceFactor: $("#e_mainPriceFactor").val(),
                rowPriceFactor: $("#e_rowPriceFactor").val(),
                colPriceFactor: $("#e_colPriceFactor").val(),
                priceLabel: $("#e_priceLabel").val(),
                priceContent: $("#e_priceContent").val(),
                priceHtmlTable: $("#DoubleList").html()
            }
            $.ajax({
                url: "apis/product/updateproductprice",
                type: 'post',
                data: {
                    "productInfo": JSON.stringify(productInfo)
                },
                dataType: 'json',
                success: function (data, status, xhr) {
                    if (data.httpCode == 200) {
                        $(".editinfo").hide();
                        $(".saveinfo").show();
                        $("#gray_bg").hide();
                        $("#editDiadog").hide();
                        window.location.reload();
                    } else {
                        alert(data.msg);
                    }
                }
            })
        }
    })
    //    删除行
    function delRow() {
        $("tbody tr th").mouseover(function () {
            $(this).children('em').show();
        }).mouseleave(function () {
            $(this).children('em').hide();
        });
        $(".delimg").click(function () {
            $(this).parents("tr").remove();
        })
    }
    //    删除列
    function delCol() {
        $("thead tr th").mouseover(function () {
            $(this).children('em').show();
        }).mouseleave(function () {
            $(this).children('em').hide();
        });
        $(".delColimg").click(function () {
            var cols = $("#doubleCol tr th");
            var colValue = $(this).parent().siblings("input").attr("value");
            var count;
            for (var i = 1; i < cols.length; i++) {
                if ($(cols[i]).children("input").attr("value") == colValue) {
                    count = i;
                }
            }
            $(cols[count]).remove();
            var rowtr = $("#DoubleListMyGrid tr");
            for (var j = 0; j < rowtr.length; j++) {
                var tds = $(rowtr[j]).children("td");
                for (var g = 0; g < tds.length; g++) {
                    if (g == count - 1) {
                        $(tds[g]).remove();
                    }
                }
            }
        })
    }
//    表格显示时过滤
    function undefind() {
        var cols = $("#doubleCol tr th");
        var rowtr = $("#DoubleListMyGrid tr");
        for (var i = 1; i < cols.length; i++) {
            if ($(cols[i]).children("span").html() == "undefined") {
                $(cols[i]).remove();
            }
        }
        for (var j = 0; j < rowtr.length; j++) {
            var tds = $(rowtr[j]).children();
            for (var g = 0; g < tds.length; g++) {
                if ($(tds[g]).children("span").html() == "undefined") {
                    $(tds[g]).remove();
                }
            }
        }
    }
    //编辑单元格后保存
    function inputBlur() {
        $(".init").blur(function () {
            $(this).attr("value", $(this).val());
            $(this).siblings("span").html($(this).val());
            $(".init").show();
            $(".thead").hide();
        })
    }
    function strToJson(str) {
        var json = eval('(' + str + ')');
        return json;
    }
    function query(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)return unescape(r[2]);
        return "";
    }
    //  垂直居中
    jQuery.fn.center = function () {
        this.css("position", "absolute");
        this.css("top", ( $(window).height() - this.height() ) / 2 + $(window).scrollTop() + "px");
        this.css("left", ( $(window).width() - this.width() ) / 2 + $(window).scrollLeft() + "px");
        return this;
    }
    $(".close").click(function () {
        $("#editDiadog").hide();
        $("#franchiseDiadog").hide();
        $("#gray_bg").hide();

        $("#rowName").val("");
        $("#singlePrice").val("");
        $("#doublerowName").val("");
    })
</script>
</body>
</html>